"""

利用微分知识求sqrt(N)的近似解
"""
from sympy import *


def sqrt(number):
    """
    # 参考 https://blog.csdn.net/qq_45589982/article/details/105793244
    :param number:
    :return:
    """
    x = number
    y = (x + number / x) / 2
    # 近似值精度
    while (x-y) > 1e-8:
        x = y
        y = (x + number / x) / 2
        print(str(x) + " " + str(y))
    return y


def sqrt_by(number):
    return number**0.5


if __name__ == "__main__":
    number = 4
    y = sqrt(number)
    print(y)
    y2 = sqrt_by(number)
    print(y2)
